<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Article extends CI_Controller {
	public $navs;
	public function __construct(){
		parent::__construct();
		$this->load->helper('url');
		$this->load->model("Catalog_model");
		$this->load->model("Article_model");
		$this->navs = $this->Catalog_model->get_All();
	}

	public function index($page=1){
		$page_size = 3;
        $total = $this->Article_model->count_All();
        $articles = $this->Article_model->get_by_page($page,$page_size);	
		$data = array(
				"navs" =>$this->navs,
				"articles" =>$articles,
				"catalog_id" =>0,
			);
		$this->load->library('pagination');
        $config['base_url'] = site_url('article/index/');
        $config['total_rows'] = $total;
        $config['per_page'] = $page_size;
        $config['use_page_numbers'] = TRUE;
        $this->pagination->initialize($config);
		$this->load->view('article_index',$data);
	}
	public function view($id){
		// $this->output->enable_profiler(TRUE);
		$article = $this->Article_model->get_One($id);
		$this->Article_model->view_once($id);
		$data = array(
				"navs" =>$this->navs,
				"article" =>$article,
				"catalog_id" =>$article->catalog_id,
			);
		$this->load->view('Article_view',$data);
	}
	public function lists($id){
		$articles = $this->Article_model->get_Catalog($id);
		$data = array(
				"navs" =>$this->navs,
				"articles" =>$articles,
				"catalog_id" =>$id,
			);
		$this->load->view("article_index",$data);
	}
}
?>